//
//  StyleViewController.m
//  Example
//
//  Created by admin on 2020/4/14.
//  Copyright © 2020 admin. All rights reserved.
//

#import "StyleViewController.h"

#import "StyleViewCollectionCell.h"

@interface StyleViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property(strong, nonatomic) UICollectionView * collectionView;
@property(strong, nonatomic) NSMutableDictionary * datadic;
@end

@implementation StyleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
    [self configUI];
}

-(void)configUI{
    self.title = @"样式概览";
    [self.view addSubview:self.collectionView];
}
-(void)loadData{
    //    #define FONT_BSYS24 [UIFont boldSystemFontOfSize:24]
    //    #define FONT_BSYS20 [UIFont boldSystemFontOfSize:20]
    //    #define FONT_BSYS18 [UIFont boldSystemFontOfSize:18]
    //    #define FONT_BSYS16 [UIFont boldSystemFontOfSize:16]
    //    #define FONT_BSYS14 [UIFont boldSystemFontOfSize:14]
    //    #define FONT_BSYS12 [UIFont boldSystemFontOfSize:12]
    //
    //
    //    #define FONT_SYS24 [UIFont systemFontOfSize:24]
    //    #define FONT_SYS20 [UIFont systemFontOfSize:20]
    //    #define FONT_SYS18 [UIFont systemFontOfSize:18]
    //    #define FONT_SYS16 [UIFont systemFontOfSize:16]
    //    #define FONT_SYS14 [UIFont systemFontOfSize:14]
    //    #define FONT_SYS12 [UIFont systemFontOfSize:12]
    //    #define FONT_SYS10 [UIFont systemFontOfSize:10]
    self.datadic = [@{
        @"颜色":@[
                @{@"key":@"PRIMARY",
                  @"value":COLORPRIMARY
                },
                @{@"key":@"SUCCESS",
                  @"value":COLORSUCCESS
                },
                @{@"key":@"WARNING",
                  @"value":COLORWARNING
                },
                @{@"key":@"DANGER",
                  @"value":COLORDANGER
                },
                @{@"key":@"INFO",
                  @"value":COLORINFO
                },
        ],
        @"字体":@[
                @{@"key":@"系统字体大小样本12",
                  @"value":FONT_SYS12
                },
                @{@"key":@"系统字体大小样本14",
                  @"value":FONT_SYS14
                },
                @{@"key":@"系统字体大小样本16",
                  @"value":FONT_SYS16
                },
                @{@"key":@"系统字体大小样本18",
                  @"value":FONT_SYS18
                },
                @{@"key":@"系统字体大小样本20",
                  @"value":FONT_SYS20
                },
                @{@"key":@"系统字体大小样本24",
                  @"value":FONT_SYS24
                },
                
                @{@"key":@"系统粗体字体大小样本12",
                  @"value":FONT_BSYS12
                },
                @{@"key":@"系统粗体字体大小样本14",
                  @"value":FONT_BSYS14
                },
                @{@"key":@"系统粗体字体大小样本16",
                  @"value":FONT_BSYS16
                },
                @{@"key":@"系统粗体字体大小样本18",
                  @"value":FONT_BSYS18
                },
                @{@"key":@"系统粗体字体大小样本20",
                  @"value":FONT_BSYS20
                },
                @{@"key":@"系统粗体字体大小样本24",
                  @"value":FONT_BSYS24
                },
        ]
    } copy];
}

-(UICollectionView *)collectionView{

    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.minimumLineSpacing = 0.f;
        flowLayout.minimumInteritemSpacing = 0.f;
        flowLayout.itemSize = CGSizeMake(KWidth, 120);
        flowLayout.headerReferenceSize = CGSizeZero;
        flowLayout.footerReferenceSize = CGSizeZero;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _collectionView.backgroundColor = UIColor.whiteColor;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.scrollsToTop = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.showsVerticalScrollIndicator = NO;
        [_collectionView registerClass:[StyleViewCollectionCell class] forCellWithReuseIdentifier:@"StyleViewCollectionCell"];
        //        _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //            weakSelf.pageNum = 0;
        //            [weakSelf.productList removeAllObjects];
        //            [self seatchProduct];
        //        }];
        //
        //        // 上拉刷新
        //        _collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        //
        //            weakSelf.pageNum ++;
        //            [self seatchProduct];
        //
        //        }];
        
    }
    return _collectionView;
}

-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}

#pragma mark collectionView

- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    StyleViewCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"StyleViewCollectionCell" forIndexPath:indexPath];
    NSString *key = [_datadic.allKeys objectAtIndex:indexPath.section];
    NSArray *arr = [_datadic objectForKey:key];
    NSDictionary *data = [arr objectAtIndex:indexPath.row];
    if ([key isEqualToString:@"颜色"]) {
        cell.backgroundColor = [data objectForKey:@"value"];
        cell.titleLab.text = [data objectForKey:@"key"];
        cell.titleLab.font = FONT_SYS14;
        cell.titleLab.textColor = UIColor.whiteColor;
    }else if ([key isEqualToString:@"字体"]){
        cell.backgroundColor = UIColor.whiteColor;
        cell.titleLab.font = [data objectForKey:@"value"];
        cell.titleLab.textColor = UIColor.blackColor;
        cell.titleLab.text = [data objectForKey:@"key"];
    }
    
    return cell;
    
}

- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    NSString *key = [_datadic.allKeys objectAtIndex:section];
    NSArray *arr = [_datadic objectForKey:key];
    return arr.count;;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return _datadic.allKeys.count;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    NSString *key = [_datadic.allKeys objectAtIndex:indexPath.section];
    if ([key isEqualToString:@"颜色"]) {
        return CGSizeMake(KWidth, 80);
    }else if ([key isEqualToString:@"字体"]){
        return CGSizeMake(KWidth, 44);
    }else{
        return CGSizeMake(KWidth/4, 44);
    }
}





@end
